package com.PAT.UnSatisfying;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/11/29/14:37
 * @Description:
 * @Target:
 */
public class 字符串压缩与解压 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String c = in.nextLine();
        String  sss  = in.nextLine();
        ArrayList arrayList = GetSplitString(sss);
        OutPrintln(c.charAt(0),arrayList);





    }




    public static void OutPrintln(char c,ArrayList arrayList){
        if ('C'==c){
            for (int i = 0; i < arrayList.size()-1; i++) {
                System.out.print(GetCompressString((String) arrayList.get(i))+" ");
            }
            if (arrayList.size()>0){
                System.out.println(GetCompressString((String) arrayList.get(arrayList.size()-1)));
            }

        }else {
            for (int i = 0; i < arrayList.size()-1; i++) {
                System.out.print(GetDecompressString((String) arrayList.get(i))+" ");
            }
            if (arrayList.size()>0){
                System.out.println(GetDecompressString((String) arrayList.get(arrayList.size()-1)));
            }
        }
    }



    // 输入的是一行,将它切开,并且返回切开的字符串数组
    public static ArrayList GetSplitString(String s1){
        String ss = "";
        ArrayList list = new ArrayList();
        for (int i = 0; i <= s1.length()-1; i++) {
            if (s1.charAt(i)!=' '){
                ss+=s1.charAt(i);
            }else {
                if (i!=0&&ss.length()>0){
                    list.add(ss);
                    ss="";
                }else {
                    ss=ss;
                }
            }

            if (i==s1.length()-1&&ss.length()>0){
                list.add(ss);
            }

        }

        return list;
    }





    // 压缩一组,如ABCCCD,压缩为AB3CD
    public  static  String GetCompressString(String s1){
        String ss = "";
        int count = 1;
        boolean flag = false;
        if (s1.length() == 1) {
            ss = s1;
        }else {
            for (int i = 1; i <= s1.length()-1; i++) {
                if (s1.charAt(i-1)==s1.charAt(i)){
                    count++;
                    flag = true;
                }else if(flag==false&&s1.charAt(i-1)!=s1.charAt(i)){
                    ss+=s1.charAt(i-1);
                }else if (flag==true&&s1.charAt(i-1)!=s1.charAt(i)){
                    ss+=count;
                    ss+=s1.charAt(i-1);
                    flag = false;
                    count=1;
                }

                if (i==s1.length()-1){
                    if (count!=1){
                        ss+=count;
                        ss+=s1.charAt(i);
                    }else {
                        ss+=s1.charAt(i);
                    }
                }
            }
        }

        return ss;
    }


    // 解压,遇到数字,解开..
    public static String GetDecompressString(String s1){
        String ss = "";

        String count = "";
        boolean flag = false;
        int i = 0;
       while (i<=s1.length()-1){
            if (s1.charAt(i)>='0'&&s1.charAt(i)<='9'){
                count+=s1.charAt(i);
                i++;
                flag = true;
            }else if (flag==true&&(s1.charAt(i)<'0'||s1.charAt(i)>'9')){
                for (int j = 1; j <= Integer.valueOf(count); j++) {
                    ss+=s1.charAt(i);
                }
                i++;
                count="";
                flag = false;
            }else if (flag==false&&(s1.charAt(i)<'0'||s1.charAt(i)>'9')){
                ss+=s1.charAt(i);
                i++;
            }
        }


        return ss;
    }



}
